package com.wondream.myframework.app.common.interceptor;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
 * @author wondream
 * @version 1.0
 * @create 2022/11/10 9:47 PM
 */
@Component
@Aspect
public class OperateAdvice {

    Logger logger = LoggerFactory.getLogger(OperateAdvice.class);

    @Around("execution(public * com.wondream.myframework.app.controller.web..*(..)) && @annotation(operateLog)")
    public Object httpAdvice(ProceedingJoinPoint pjp, OperateLog operateLog) throws Throwable {
        logger.info(">>>> operateClass : {}", pjp.getTarget().getClass().getName());
        logger.info(">>>> method :{}", ((MethodSignature) pjp.getSignature()).getMethod());
        logger.info(">>>> args :{}", Arrays.toString(pjp.getArgs()));
        Object result = pjp.proceed();
        logger.info(">>>> args :{}", result);
        return result;
    }

}
